import React, { Component } from 'react'
import { connect } from 'react-redux'

export class Input extends Component {
    render() {
        const { count, num, change, init } = this.props
        return (
            <div>
                Input --- { count } --- { num }
                <button onClick={ change }>修改</button>
                <button onClick={ init }>Saga---</button>
            </div>
        )
    }
}

const mapStateToProps = (state) => {
    const { count, num } = state
    return {
        count,
        num
    }
}

const mapDispatchToProps = (dispatch) => {
    return {
        change() {
            dispatch({ type: "CHANGE_NUM" })
        },
        init() {
            dispatch({ type: "ASYNC_INIT" })
        }
    }
}

export default connect(mapStateToProps, mapDispatchToProps)(Input)